@extends('admin/common')

@section('content')
    <article class="page-container">
        <form action="" method="post" class="form form-horizontal" id="form-cate-add">
            <input type="hidden" name="id" value="{{ isset($id)?$id : '' }}">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span> 分类名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{ isset($cate_info->name)?$cate_info->name:'' }}" placeholder="" id="name" name="name">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"> 所属分类：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <select class="input-text" name="pid" id="pid">
                        <option value="0">/</option>
                        @if(isset($allcate))
                            @foreach($allcate as $k => $v)
                                @if(isset($cate_info->pid) && $cate_info->pid == $v['id'])
                                    <option value="{{ $v['id'] }}" selected>{{ $v['name'] }}</option>
                                @else
                                    <option value="{{ $v['id'] }}">{{ $v['name'] }}</option>
                                @endif
                                @if(isset($v['child']) && is_array($v['child']))
                                    @foreach($v['child'] as $k_c => $k_v)
                                        @if(isset($cate_info->pid) && $cate_info->pid == $k_v['id'])
                                            <option value="{{ $k_v['id'] }}" selected>--{{ $k_v['name'] }}</option>
                                        @else
                                            <option value="{{ $k_v['id'] }}">--{{ $k_v['name'] }}</option>
                                        @endif
                                    @endforeach
                                @endif
                            @endforeach
                        @endif
                    </select>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
                </div>
            </div>
        </form>
    </article>
@endsection

@section('script')
    <script type="text/javascript" src="{{ asset('admin/lib/jquery.validation/1.14.0/jquery.validate.js') }}"></script>
    <script type="text/javascript" src="{{ asset('admin/lib/jquery.validation/1.14.0/validate-methods.js') }}"></script>
    <script type="text/javascript" src="{{ asset('admin/lib/jquery.validation/1.14.0/messages_zh.js') }}"></script>
    <script type="text/javascript">
        $(function(){
            $("#form-cate-add").validate({
                rules:{
                    name : {
                        required:true
                    }
                },
                onkeyup:false,
                focusCleanup:true,
                success:"valid",
                submitHandler:function(form){
                    $(form).ajaxSubmit({
                        type : 'post',
                        url : "{{ URL::to('admin/articleCate/addCatePost') }}" ,
                        success : function(ret){
                            if(ret.code == 1){
                                layer.msg(ret.msg,{icon:1,time:1000},function(){
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                });
                            }else{
                                layer.msg(ret.msg,{icon:1,time:1000});
                            }
                        }
                    });
                }
            });
        });
    </script>
@endsection